package Long.Lu.Service.Impl;


import Long.Lu.Dao.RecruitManagerDao;
import Long.Lu.Service.RecruitService;
import Long.Lu.pojo.RecruitManager;
import Long.Lu.pojo.RecruitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class RecruitServiceImpl implements RecruitService {
    //注入dao
    @Autowired
    private RecruitManagerDao recruitManagerDao;

    @Override
    public List<RecruitManager> select() {
        //查询所有
        return recruitManagerDao.findAll();
    }

    @Override
    public boolean update(Integer rId) {
        try {
            RecruitManager re = recruitManagerDao.findById(rId).get();
            if (re != null) {
                Integer state = re.getState();
                if (state == 0) {
                    re.setState(1);
                }else{
                    re.setState(0);
                }
                recruitManagerDao.save(re);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean add(RecruitParam recruitParam) {
        try {
            RecruitManager rm= new RecruitManager();
            rm.setEmployName(recruitParam.getEmployName());
            rm.setAge(recruitParam.getAge());
            rm.setDate(recruitParam.getDate());
            rm.setDepartment(recruitParam.getDepartment());
            rm.setEducation(recruitParam.getEducation());
            rm.setDuty(recruitParam.getDuty());
            rm.setEmail(recruitParam.getEmail());
            rm.setSex(recruitParam.getSex());
            rm.setPhone(recruitParam.getPhone());
            rm.setrDate(recruitParam.getrDate());
            rm.setState(recruitParam.getState());

            recruitManagerDao.save(rm);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }

    //删除
    @Override
    public boolean deletes(Integer rId) {
        recruitManagerDao.deleteById(rId);
        return false;
    }

    //品两删除
    @Override
    public boolean deletess(String rIds) {
        try{
            if(rIds!=null && !rIds.equals("")) {
                String[] arr = rIds.split(",");
                recruitManagerDao.deleteAll(Arrays.asList(arr));
                return true;
            }else{
                return false;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;

    }

}
